//
//  WPTransHistoryViewController.m
//  ZhongChouPingTai
//
//  Created by WeiPan on 16/4/8.
//  Copyright © 2016年 WPJoe. All rights reserved.
//

#import "WPTransHistoryViewController.h"
#import "WPTransHistoryModel.h"
#import "WPTransHistoryViewModel.h"
#import "WPTransHistoryTableViewCell.h"

static NSString *const kUITableViewCellIdentifier = @"cellIdentifier";

@interface WPTransHistoryViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) UILabel * noMoreLabel;/**< 没数据说明 */
@property (nonatomic, strong) UITableView * historyTableView;/**< 转让历史列表 */
@property (nonatomic, strong) NSMutableArray * historyDataSource;/**< 转让历史数据源 */
- (void)initializeDataSource; /**< 初始化数据源 */
- (void)initializeUserInterface; /**< 初始化用户界面 */
- (void)refreshData;/**< 刷新数据 */
@end

@implementation WPTransHistoryViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initializeDataSource];
    [self initializeUserInterface];
}
#pragma mark - init
- (void)initializeDataSource {
    self.historyDataSource = [NSMutableArray array];
    WPTransHistoryModel * model = [WPTransHistoryModel new];
    model.poster = @"banner1";
    model.title = @"Rain 王者归来亚洲巡回演唱会";
    model.buyInPrice = @"800";
    model.time = @"2015-11-2";
    model.position = @"A-A23";
    model.sellPrice = @"1000";
    NSArray * arr1 = [NSArray arrayWithObjects:model, model, nil];
    NSArray * arr = [NSArray arrayWithObjects:model, model, model,nil];
    [_historyDataSource addObject:arr];
    [_historyDataSource addObject:arr1];
    [_historyDataSource addObject:arr];

    [_historyDataSource addObject:arr];
}
- (void)initializeUserInterface {
    [self.view addSubview:self.noMoreLabel];
    [self.view addSubview:self.historyTableView];
    UIBarButtonItem * item = [[UIBarButtonItem alloc]initWithTitle:@"时间" style:UIBarButtonItemStyleDone target:self action:@selector(respondsToRightItem)];
    self.navigationItem.rightBarButtonItem = item;
}
#pragma mark - respond events
- (void)respondsToRightItem {
}
#pragma mark - 刷新数据
- (void)refreshData {
    
}
#pragma mark - 协议UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return _historyDataSource.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [_historyDataSource[section] count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    WPTransHistoryTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kUITableViewCellIdentifier];
    if (!cell) {
        cell = [[WPTransHistoryTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kUITableViewCellIdentifier];
    }
    cell.accessoryType = UITableViewCellAccessoryNone;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    [cell setModel:_historyDataSource[indexPath.section][indexPath.row]];
    return cell;
}
#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 20*DHFlexibleHorizontalMutiplier();
}
//设置每一行高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 75*DHFlexibleHorizontalMutiplier();
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *headView = [[UIView alloc]init];
    UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(20*DHFlexibleHorizontalMutiplier(), 0, 200, 20*DHFlexibleHorizontalMutiplier())];
    lab.font = [UIFont systemFontOfSize:11*DHFlexibleHorizontalMutiplier()];
    lab.textColor = COLOR_RGB(102, 102, 102, 1);
    lab.text = @"2015年11月";
    [headView addSubview:lab];
    return headView;
}
#pragma mark - getter
- (UITableView *)historyTableView {
    if (!_historyTableView) {
        _historyTableView = ({
            UITableView * tableview = [[UITableView alloc]initWithFrame:CGRectMake(0, navBar_Fheight, SCREEN_SIZE.width, SCREEN_SIZE.height - navBar_Fheight) style:UITableViewStylePlain];
            tableview.dataSource = self;
            tableview.delegate = self;
            tableview.tableFooterView = [UIView new];
            tableview.pagingEnabled = NO;
            tableview.bounces = NO;
            tableview.backgroundColor = [UIColor clearColor];
            tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
            tableview;
        });
    }
    return _historyTableView;
}
@end
